Set wd and load packages.
Intensity and rain data is handled here.
Set polygonID. Data is clipped accordingly
dates <- c(ymd("2018-01-03"), ymd("2018-01-15"), ymd("2018-01-27"), ymd("2018-02-08"), ymd("2018-02-20"), ymd("2018-03-04"), ymd("2018-03-16"), ymd("2018-03-28"), ymd("2018-04-09"), ymd("2018-04-21"), ymd("2018-05-03"), ymd("2018-05-15"), ymd("2018-05-27"), ymd("2018-06-08"), ymd("2018-06-20"), ymd("2018-07-02"), ymd("2018-07-14"), ymd("2018-07-26"), ymd("2018-08-07"), ymd("2018-08-19"), ymd("2018-08-31"), ymd("2018-09-12"), ymd("2018-09-24"), ymd("2018-10-06"), ymd("2018-10-18"), ymd("2018-10-30"), ymd("2018-11-11"), ymd("2018-11-23"), ymd("2018-12-05"), ymd("2018-12-17"), ymd("2018-12-29"))
loadPolygon <- function(shape) {
# This polygon is being looked at: polyID
int_vv <- st_as_stars(int_VV[shape])
int_vh <- st_as_stars(int_VH[shape])
int_vv <- st_set_dimensions(int_vv, 3, val = dates, names = "time")
int_vh <- st_set_dimensions(int_vh, 3, val = dates, names = "time")
# c()
comb <- c(int_vv, int_vh, along="bands")
# switch bands to attributes, this is more of a design choice.
comb_split <- split(comb, "bands")
names(comb_split) <- c("VV", "VH")
return(comb_split)
}
comb_split10 <- loadPolygon(water[10,])
# whole year, both pols
# VV
plot(comb_split10[1,,,])
# VH
plot(comb_split10[2,,,])
Function to plot a normalized change ratio.
# VV, from 1 to 31
plotCD(comb_split10, 1, 1, 5)
Function to plot a timeseries of pixel for a certain polygon
# both are thesis: water
ploTShape(comb_split10, moni[8,], moni[11,])
ploTShape(comb_split10, moni[10,], moni[9,])
# ploTShape(comb_split10, moni[4,], moni[6,])
plotbox <- function(starsObj, date, polygon1, polygon2) {
poly1 <- starsObj[polygon1]
poly2 <- starsObj[polygon2]
poly1.df <- as.data.frame(poly1[,,,date])
poly1.df$cat <- "polygon 1"
poly2.df <- as.data.frame(poly2[,,,date])
poly2.df$cat <- "polygon 2"
poly <- rbind(poly1.df, poly2.df)
ggplot(poly, aes(x=poly$cat, y=poly$VV)) + geom_boxplot()
}
plotbox(comb_split10, 1, moni[2,], shape[124,])
# plotbox(comb_split10, 3, moni[2,], shape[124,])
# plotbox(comb_split10, 6, moni[2,], shape[124,])
plotthree <- function(obj, start, end) {
colo = viridisLite::inferno(85)
breaks = seq(-25, -8, 0.2)
threshold = -15
for (i in start:end) {
plot(obj[1,,,i])
image(obj[1,,,i], col = colo, breaks = breaks)
image(obj[1,,,i], col = c("white", "black"), breaks = c(-22, threshold, 0))
}
}
# plotthree(comb_split10, 1, 7)
comb_split124 <- loadPolygon(moni[8,])
# VV
plotCD(comb_split10, 1, 9, 11)
# VH
plotCD(comb_split10, 2, 9, 11)
# plots: stars-plot, stars-image with unified scale, masked image
plotthree(comb_split10, 1, 31)
comb_split123 <- loadPolygon(moni[9,])
# VV
plotCD(comb_split123, 1, 9, 11)
# VH
plotCD(comb_split123, 2, 9, 11)
# plots: stars-plot, stars-image with unified scale, masked image
plotthree(comb_split123, 9, 11)
comb_split112 <- loadPolygon(moni[10,])
# VV
plotCD(comb_split112, 1, 9, 11)
# VH
plotCD(comb_split112, 2, 9, 11)
# plots: stars-plot, stars-image with unified scale, masked image
plotthree(comb_split112, 9, 11)
comb_split108 <- loadPolygon(moni[11,])
# VV
plotCD(comb_split108, 1, 9, 11)
# VH
plotCD(comb_split108, 2, 9, 11)
# plots: stars-plot, stars-image with unified scale, masked image
plotthree(comb_split108, 9, 11)